<?php
include(dirname(__FILE__) . "/util.php");
include_once(dirname(__FILE__) . "/article-main-adapter.php");

$conn = mysql_connect("127.0.0.1","root","");
mysql_select_db("xingtan");
$article_id = intval($_GET['id']);

$service_adapter = new ArticleMainAdapter();
$content = $service_adapter->GetContent($article_id);

$article_meta = GetArticleMeta($article_id);

$sql=sprintf("SELECT a.id AS a_id, a.title AS a_title, a.url AS a_url, a.create_time AS a_create_time,
    u.id AS u_id, u.name AS u_name, u.title AS u_title, u.url AS u_url
    FROM articles AS a, authors AS u WHERE a.category >= 0 AND a.author = u.id AND a.id > %d LIMIT 1", $article_id);
$result = mysql_query($sql);
if($result) {
  $newer_row = mysql_fetch_array($result);
}

$sql=sprintf("SELECT a.id AS a_id, a.title AS a_title, a.url AS a_url, a.create_time AS a_create_time,
    u.id AS u_id, u.name AS u_name, u.title AS u_title, u.url AS u_url
    FROM articles AS a, authors AS u WHERE a.category >= 0 AND a.author = u.id AND a.id < %d ORDER BY a.id DESC LIMIT 1", $article_id);

if (!($category_map = apc_fetch('category-map'))) {
  $category_map = array();
  $sql=sprintf("SELECT id, name, title FROM categories;");
  $result = mysql_query($sql);
  while($r = mysql_fetch_array($result)) {
    $category_map[$r['id']] = $r;
  }
  apc_add('category-map', $category_map, 3600);
}

$result = mysql_query($sql);
if($result) {
  $elder_row = mysql_fetch_array($result);
}

mysql_close($conn);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
printf('<title>编辑-%s</title>', $article_meta['a_title']);
?>

<link href="/css/core.css?v=7" rel="stylesheet" type="text/css"></link>
<script type="text/javascript" src="http://www.jztzp.com/ckeditor/ckeditor.js"></script>
<style type="text/css">
.rankicon {
  cursor: pointer;cursor: hand;float:left;clear:none;
  background: url(/img/rank-star.gif) no-repeat 1px 0px;
  height:13px;width:0px;margin:0;padding:0 0 0 15px;line-height: 20px;vertical-align: middle;margin:2px 0;
  border:1px solid #F6F9F7;
  opacity:0.2;
  filter:alpha(opacity=20);
}
.rankicon:hover {
  border:1px solid green;
}
div #rank-bar {
  margin:8px 0px;height:16px;line-height:18px;font-size:12px;border:0px solid red;text-align:left;
  width:33%;float:right;margin:14px 6px;
}
div.rank-plot {
  border:1px solid green;
  float:left;
  clear:none;
  margin:5px 3px 2px 0;
  width:100px;
  height:6px;
  overflow:hidden;
  background: url(/img/rank-bar.gif) repeat-y -100px;
}
div.rank-desc {
  float:left;
  margin-right:5px;
}
div.source-desc {
  font-weight:bold;
  clear:both;
  margin:3px auto 12px;
  color:#777;
  font-size:12px;
}
div.neighbors-nav {
  margin:8px 6px;height:10px;font-size:12px;
  clear:both;
}

div.neighbor-prev {
  float:left;
}

div.neighbor-next {
 float:right;position:relative;
}

div.article-title-bar {
  clear:both;height:36px;background-color:#F6F9F7;
  margin-bottom:8px; padding:2px 8px 8px;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;
}
div.article-title-body {
  margin:0;float:left;
}
h2.article-title-text {
  margin:2px 0;line-height:38px;font-weight:bold;
}

div.main-related {
  float:right;
  clear:right;
  border: 1px solid #CDC;
  float: right;
  margin: 0 0 0 4px;
  width:24%;

  margin-bottom:8px; padding:8px; background-color:white;-moz-border-radius: 6px;-webkit-border-radius: 6px;border-radius: 6px;
}
ul.related-list{
  padding: 2px 8px;
}
li.related-item {
  list-style:circle;margin-left:10px;margin-bottom: 4px;
}
div.content img {
  visibility:hidden;
}

li#old-home-entrance a {
  color: #e9e9e9;
  text-decoration:underline;
}
li#old-home-entrance a:hover {
  color: #fff;
}

li#old-home-entrance {
 font-size:12px;font-weight:normal;float:right;margin-right:0px;
}
.tooltip {
    background: url("/img/tooltip.png") no-repeat left top transparent;
    color: #FFFFFF;
    display: block;
    position: relative; 
    line-height:18px;
    right: -49px;
    top: -46px;
    text-align: center;
    height: 28px;
    width: 26px;
    z-index: 999;
}

#sns-share-bar {
  float:left;clear:both;margin:6px 0 16px 6px;
}
a.sns-share {
  cursor: pointer;
  float: left;
  height: 16px;
  margin: 0 1px 0 6px;
  overflow: hidden;
  width: 16px;
  background: url("/img/sns-share.png") no-repeat scroll 9999px 9999px transparent;
}
#renren-share {
  background-position: 0 -56px;
}
#douban-share {
  background-position: 0 -143px;
}
#sina-t-share {
  background-position: 0 -249px;
}
#qq-t-share {
  background-position: 0 -342px;
}
</style>
<script type="text/javascript">
<?php
printf("var article_id = %d;", $article_id);
?>
</script>
</head>
<body>

<?php
include("content-header.php");
?>

<div class="container">
  <div class="main">
    <div class="article-title-bar">
      <div class="article-title-body">
        <h2 class="article-title-text">
          <?php print($article_meta['a_title']); ?>
        </h2>
      </div>
    </div>

    <div style="width:96%" class="content article_body">
      <div class="source-desc">
	  <?php
	    printf('类别 : <a href="/cat%d/">%s</a> ', 
              $article_meta['a_category'], 
              $category_map[$article_meta['a_category']]['name']);
	    if ($article_meta['u_id'] > 0) {
	      printf(' &nbsp; 作者: <a target="_blank" title="%s:%s" href="/u%d/">%s</a>', 
                $article_meta['u_name'], $article_meta['u_title'],
		$article_meta['u_id'], $article_meta['u_name']);
	    }
	    printf('&nbsp; <span style="font-size:12px;">%s </span>', 
                $article_meta['a_create_time']);  
	    ?>
      </div>
      <form method="post" action="/content-update.php?id=<?php printf('%d',$article_id); ?>">
        <p>
          <textarea id="jz_editor" name="jz_editor" rows="80">
            <?php print($content); ?>
          </textarea>
        </p>
        <p><input type="submit" /></p>
      </form>
    </div>
  </div>

</div>
<script type="text/javascript">
CKEDITOR.replace('jz_editor', {'language':'zh-cn', 'height':'800px'});
</script>
</body>
</html>
